package ua.khpi.si.kit49.diploma.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import ua.khpi.si.kit49.diploma.db.dao.ConnectionDAO;
import ua.khpi.si.kit49.diploma.db.dto.City;
import ua.khpi.si.kit49.diploma.db.dto.Connection;

/**
 * Implementation of connection service
 * 
 * @author netstalk3r
 * 
 */

@Service("connectionService")
public class ConnectionServiceImpl implements ConnectionService {

	public ConnectionServiceImpl() {
		super();
	}

	@Autowired(required = true)
	private ConnectionDAO connectionDAO;

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
	public List<Connection> getAllConnection() {
		return connectionDAO.getAllConnection();
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
	public Connection getConnectionById(Integer id) {
		return connectionDAO.getConnectionById(id);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
	public Connection getConnectionByStartAndFinish(Integer start,
			Integer finish) {
		City startCity = CityHolder.getInstance().getCityById(start);
		City finishCity = CityHolder.getInstance().getCityById(finish);
		return connectionDAO.getConnectionByStartAndFinish(startCity,
				finishCity);
	}
}
